﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;


namespace MaxStudio.Concrete.Server.Service
{
    public class RMService : ServiceHandle, IRM
    {
        #region IRM Members

        public OperationResult<List<tb_RM>> GetAllRM()
        {
            ConcreteDaoDataContext dataContext = new ConcreteDaoDataContext();

            OperationResult<List<tb_RM>> result = new OperationResult<List<tb_RM>>();
            List<tb_RM> list = new List<tb_RM>();
            try
            {
                list = dataContext.GetAllRM();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;

        }

        public OperationResult<tb_RM> GetRMById(int id)
        {
            ConcreteDaoDataContext dataContext = new ConcreteDaoDataContext();

            OperationResult<tb_RM> result = new OperationResult<tb_RM>();
            tb_RM rM;
            try
            {
                rM = dataContext.GetRMById(id);
                if (rM == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = rM;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RM>> GetRMByTypeId(int typeId)
        {
            ConcreteDaoDataContext dataContext = new ConcreteDaoDataContext();

            OperationResult<List<tb_RM>> result = new OperationResult<List<tb_RM>>();
            List<tb_RM> list = new List<tb_RM>();
            try
            {
                list = dataContext.GetRMByTypeId(typeId);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }


        public OperationResult<tb_RM> CreateRM(tb_RM entity)
        {
            OperationResult<tb_RM> result = new OperationResult<tb_RM>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.CreateRM(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RM> ModifyRM(tb_RM entity)
        {
            OperationResult<tb_RM> result = new OperationResult<tb_RM>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyRM(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RM> DeleteRM(tb_RM entity)
        {
            OperationResult<tb_RM> result = new OperationResult<tb_RM>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeleteRM(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion

        
    }
}
